package dao;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.Session;
import dao.utils.GenericHibernateDAO;

import dao.utils.GenericHibernateDAO;
import domain.Compra;
import domain.Proveedor;

public class CompraDAOImpl extends GenericHibernateDAO implements CompraDAO {

	public CompraDAOImpl(Session s) {
		super(s);
	}
	
	@SuppressWarnings("unchecked")
	public List<Compra> findAll(){
		Query q=getSession().createQuery("From Compra");
		return q.list();
	}
	
	@SuppressWarnings("unchecked")
	public boolean deleteComp(int id, Compra proov) {
		try {
			Query q = getSession().createQuery("select count(comp.idCompra) from Compra as comp where comp.idCompra = ?")
					.setInteger(0, id);
			Long numProov = (Long) q.uniqueResult();
			if (numProov == 0) {
				return false;
			} else {
				getSession().delete(proov);
				return true;
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return false;
		}
	}

}
